<include file="Public/header"/>
<div class="layui-tab">
	<ul class="layui-tab-title">
		<li class="" data-url="<{:U('User/editUser',array('uid'=>$_GET['uid']))}>" onclick="load_url(this)">商户信息</li>
		<li class="" data-url="<{:U('User/userWithdrawal',array('uid'=>$_GET['uid']))}>" onclick="load_url(this)">提现</li>
		<li class="layui-this" data-url="<{:U('User/editUserProduct',array('uid'=>$_GET['uid']))}>" onclick="load_url(this)">通道</li>
		<li class="" data-url="<{:U('User/userRateEdit',array('uid'=>$_GET['uid']))}>" onclick="load_url(this)">费率</li>
	</ul>
	<div class="layui-tab-content">
		<div class="layui-tab-item layui-show">
			<form class="layui-form" action="" id="userProduct">
				<input type="hidden" name="userid" value="<{$_GET['uid']}>">
				<table class="table table-hover choosetable" >
				<thead>
				<tr>
					<th>接口名称</th>
					<th>接口状态</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody>
				<volist name="products" id="p">
				<tr>
					<td><{$p.name}></td>
					<td>
						<input type="checkbox"
							   data-pid="<{$p.id}>"
						<if condition="$p['status']">checked</if>
						name="u[<{$p.id}>][status]"
						lay-skin="switch"
						lay-filter="switchStatus"
						lay-text="开启|关闭" value="1">
					</td>
					<td>
						<input type="radio" name="u[<{$p.id}>][polling]" lay-filter="polling" data-pid="<{$p.id}>"
							   data-type="<{$p.paytype}>"
						<if
								condition="$p[polling] eq 0">checked</if> value="0" title="单独">
						<input type="radio" name="u[<{$p.id}>][polling]" lay-filter="polling" data-pid="<{$p.id}>"
							   data-type="<{$p.paytype}>"
						<if condition="$p[polling] eq 1">checked</if>
						value="1" title="轮询">
						<div id="selmodel<{$p.id}>" style="display:<if condition="$p['polling']">none</if>;">
						<select name="u[<{$p.id}>][channel]" lay-verify="" id="channels<{$p.id}>" lay-search="">
							<option value="">直接选择或搜索选择</option>
							<volist name="channellist" id="c">
								<if condition="$c['paytype'] eq $p['paytype']">
									<option <if condition="$p[channel] eq $c[id]">selected</if> value="<{$c.id}>"><{$c.title}></option>
								</if>
							</volist>
						</select>
						</div>
						<table class="layui-table" lay-skin="line" id="pdtable<{$p.id}>" style="display:<if
										condition="!$p['polling']">none</if>;">
						<thead>
						<tr>
							<th></th>
							<th>通道代码</th>
							<th>通道名称</th>
							<th>间隔时间</th>
						</tr>
						</thead>
						<tbody>
						<volist name="channellist" id="c">
							<if condition="$c['paytype'] eq $p['paytype']">
								<tr>
									<td><input type="checkbox" name="u[<{$p.id}>][w][<{$c.id}>][pid]" <if
											condition="$p['weight'][$c['id']][pid]">checked</if>
										lay-skin="primary" value="<if condition="$p['weight'][$c['id']]"><{$p['weight'][$c['id']][pid]}><else/><{$c['id']}></if>"></td>
									<td><{$c.id}></td>
									<td><{$c.title}></td>
									<td><input type="number" min="0" max="9" name="u[<{$p.id}>][w][<{$c.id}>][weight]"
											   class="layui-input" value="<{$p['weight'][$c['id']][weight]}>"></td>
								</tr>
							</if>
						</volist>

						</tbody>
						</table>
					</td>

				</tr>
				</volist>
				</tbody>
			</table>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label"></label>
					<button  class="btn btn-primary" lay-submit="submit" lay-filter="save">提交保存</button>
				</div>
			</div>
			</form>
		</div>
	</div>
</div>
<include file="Public/footer"/>
<script>
    var channels = <{$channels}>;
    layui.use(['layer', 'form','laydate'], function(){
        var form = layui.form
            ,laydate = layui.laydate
            ,layer = layui.layer;

        //监听提交
        form.on('submit(save)', function(data){
            $.ajax({
                url:"<{:U('User/saveUserProduct')}>",
                type:"post",
                data:$('#userProduct').serialize(),
                success:function(res){
                    if(res.status){
                        layer.alert("编辑成功", {icon: 6},function () {
                            parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.alert("操作失败", {icon: 5},function () {
                            parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                }
            });
            return false;
        });
        //监听radio
        form.on('radio(polling)', function(data){
            //console.log(data.elem); //得到radio原始DOM对象
            //console.log(data.value); //被点击的radio的value值
            var pty = $(this).attr('data-type');
            var pid = $(this).attr('data-pid');
            var html = '';
            if(data.value == 0){
                $('#selmodel'+pid).css('display','');
                $('#pdtable'+pid).css('display','none');
                html += '<option value="">直接选择或搜索选择</option>';
                for(var i in channels){
                    if(pty==channels[i].paytype){
                        html += '<option value='+channels[i].id+'>'+channels[i].title+'</option>';
                    }
                }
                $('#channels'+pid).html(html);
            }else{
                $('#selmodel'+pid).css('display','none');
                $('#pdtable'+pid).css('display','');
                for(var i in channels){
                    if(pty == channels[i].paytype){
                        html += '<tr>';
                        html += '<td><input type="checkbox" name="u['+pid+'][w]['+channels[i].id+'][pid]" ' +
                            'lay-skin="primary" ' +
                            'value="'+channels[i].id+'"></td>';
                        html += '<td>'+channels[i].id+'</td>'
                        html += '<td>'+channels[i].title+'</td>';
                        html += '<td><input type="number" min="0" max="9" name="u['+pid+'][w]['+channels[i]
                                .id+'][weight]" ' +
                            'class="layui-input" value=""></td>';
                        html += '</tr>';
                    }
                }
                $('#pdtable'+pid+' > tbody').html(html);
            }
            form.render();
        });
    });

    function load_url(url) {
        var url = $(url).data('url');
        location.href = url;
    }

</script>
</body>
</html>
